/*
 * ElectsysGUIView.java
 */
package electsysgui;

import electsys.*;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.Task;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.List;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class ElectsysGUIView extends FrameView {

    public ElectsysGUIView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ElectsysGUIApp.getApplication().getMainFrame();
            aboutBox = new ElectsysGUIAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ElectsysGUIApp.getApplication().show(aboutBox);
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "isLessonInserting")
    public Task addLessonsToCal() {
        return new AddLessonsToCalTask(getApplication());
    }

    private class AddLessonsToCalTask extends org.jdesktop.application.Task<Object, Void> {

        Calendar cal = null;

        AddLessonsToCalTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to AddLessonsToCalTask fields, here.
            super(app);
            setIsLessonInserting(false);
            cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, Integer.parseInt(jComboBox3.getSelectedItem().toString()));
            cal.set(Calendar.MONTH, Integer.parseInt(jComboBox4.getSelectedItem().toString()) - 1);
            cal.set(Calendar.DATE, Integer.parseInt(jComboBox5.getSelectedItem().toString()));
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            if (!gcal.login) {
                return "NOTLOGIN";
            }
            if (EventType == 1) {
                gcal.insertEvents(gcal.getEventWhenFromLessonTB(lt, null, cal));
            } else if (EventType == 2) {
                gcal.insertEvents(gcal.getEventRecuFromLessonTB(lt, null, cal));
            }
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground
            if (result != null && result.equals("NOTLOGIN")) {
                setMessage("请重新登录Google帐户");
            } else {
                setMessage(ElectsysGUIView.ActionSuccess);
            }
            setIsLessonInserting(true);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        mainPanel = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        loginMenuItem = new javax.swing.JMenuItem();
        lessonMenuItem = new javax.swing.JMenuItem();
        examMenuItem = new javax.swing.JMenuItem();
        advancedMenuItem1 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        helpMenuItem1 = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        LoginTab = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        if (dm==null) dm = new DataManage();
        UserList1 = new javax.swing.JComboBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        LoginButton1 = new javax.swing.JToggleButton();
        status1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        status2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        if (dm==null) dm = new DataManage();
        UserList2 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jPasswordField2 = new javax.swing.JPasswordField();
        LoginButton2 = new javax.swing.JToggleButton();
        saveButton1 = new javax.swing.JRadioButton();
        saveButton2 = new javax.swing.JRadioButton();
        imageLabel1 = new javax.swing.JLabel();
        imageLabel2 = new javax.swing.JLabel();
        LessonTab = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton4 = new javax.swing.JButton();
        ExamTab = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jComboBox6 = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jComboBox7 = new javax.swing.JComboBox();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jSeparator4 = new javax.swing.JSeparator();
        jButton7 = new javax.swing.JButton();
        AdvancedTab = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JSeparator();
        jLabel18 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jSeparator6 = new javax.swing.JSeparator();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        HelpTab = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jDialog1 = new javax.swing.JDialog();
        jLabel13 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(800, 550));

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 254, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(electsysgui.ElectsysGUIApp.class).getContext().getResourceMap(ElectsysGUIView.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        loginMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        loginMenuItem.setText(resourceMap.getString("loginMenuItem.text")); // NOI18N
        loginMenuItem.setName("loginMenuItem"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTabbedPane1, org.jdesktop.beansbinding.ELProperty.create("${selectedIndex}==0"), loginMenuItem, org.jdesktop.beansbinding.BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        loginMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(loginMenuItem);

        lessonMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        lessonMenuItem.setText(resourceMap.getString("lessonMenuItem.text")); // NOI18N
        lessonMenuItem.setName("lessonMenuItem"); // NOI18N
        lessonMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lessonMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(lessonMenuItem);

        examMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        examMenuItem.setText(resourceMap.getString("examMenuItem.text")); // NOI18N
        examMenuItem.setName("examMenuItem"); // NOI18N
        examMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                examMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(examMenuItem);

        advancedMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        advancedMenuItem1.setText(resourceMap.getString("advancedMenuItem1.text")); // NOI18N
        advancedMenuItem1.setName("advancedMenuItem1"); // NOI18N
        advancedMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                advancedMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(advancedMenuItem1);

        jSeparator2.setName("jSeparator2"); // NOI18N
        fileMenu.add(jSeparator2);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(electsysgui.ElectsysGUIApp.class).getContext().getActionMap(ElectsysGUIView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N
        helpMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuActionPerformed(evt);
            }
        });

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        helpMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        helpMenuItem1.setText(resourceMap.getString("helpMenuItem1.text")); // NOI18N
        helpMenuItem1.setName("helpMenuItem1"); // NOI18N
        helpMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuItem1ActionPerformed(evt);
            }
        });
        helpMenu.add(helpMenuItem1);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 811, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 641, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        jTabbedPane1.setName("jTabbedPane1");

        LoginTab.setName("LoginTab"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        UserList1.setEditable(true);
        UserList1.setMaximumRowCount(20);
        UserList1.setName("UserList1"); // NOI18N
        UserList1.setPreferredSize(new java.awt.Dimension(150, 21));
        UserList1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                UserList1ComponentShown(evt);
            }
        });
        UserList1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UserList1ActionPerformed(evt);
            }
        });
        RefreshUserList1();

        jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
        jPasswordField1.setName("jPasswordField1"); // NOI18N
        eups = dm.getElectUserPass(null);
        if (eups.size() > 0 ) jPasswordField1.setText(eups.get(0)[1]);

        LoginButton1.setAction(actionMap.get("LoginElectsys")); // NOI18N
        LoginButton1.setText(resourceMap.getString("LoginButton1.text")); // NOI18N
        LoginButton1.setName("LoginButton1"); // NOI18N

        status1.setText(resourceMap.getString("status1.text")); // NOI18N
        status1.setName("status1"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        status2.setText(resourceMap.getString("status2.text")); // NOI18N
        status2.setName("status2"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        UserList2.setEditable(true);
        UserList2.setName("UserList2"); // NOI18N
        UserList2.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                UserList2ComponentShown(evt);
            }
        });
        UserList2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UserList2ActionPerformed(evt);
            }
        });
        RefreshUserList2();

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jPasswordField2.setText(resourceMap.getString("jPasswordField2.text")); // NOI18N
        jPasswordField2.setName("jPasswordField2"); // NOI18N
        gups = dm.getGoogleUserPass(null);
        if (gups.size() > 0) jPasswordField2.setText(gups.get(0)[1]);

        LoginButton2.setAction(actionMap.get("LoginGoogle")); // NOI18N
        LoginButton2.setText(resourceMap.getString("LoginButton2.text")); // NOI18N
        LoginButton2.setName("LoginButton2"); // NOI18N

        saveButton1.setSelected(true);
        saveButton1.setText(resourceMap.getString("saveButton1.text")); // NOI18N
        saveButton1.setName("saveButton1"); // NOI18N

        saveButton2.setSelected(true);
        saveButton2.setText(resourceMap.getString("saveButton2.text")); // NOI18N
        saveButton2.setName("saveButton2"); // NOI18N

        imageLabel1.setIcon(resourceMap.getIcon("imageLabel1.icon")); // NOI18N
        imageLabel1.setText(resourceMap.getString("imageLabel1.text")); // NOI18N
        imageLabel1.setName("imageLabel1"); // NOI18N

        imageLabel2.setIcon(resourceMap.getIcon("imageLabel2.icon")); // NOI18N
        imageLabel2.setText(resourceMap.getString("imageLabel2.text")); // NOI18N
        imageLabel2.setName("imageLabel2"); // NOI18N

        if (gcal == null) gcal = new GCalendar();

        javax.swing.GroupLayout LoginTabLayout = new javax.swing.GroupLayout(LoginTab);
        LoginTab.setLayout(LoginTabLayout);
        LoginTabLayout.setHorizontalGroup(
            LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LoginTabLayout.createSequentialGroup()
                .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(42, 42, 42)
                                .addComponent(jLabel4))
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(imageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(57, 57, 57)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addComponent(LoginButton2)
                                .addGap(18, 18, 18)
                                .addComponent(saveButton2))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(status2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, LoginTabLayout.createSequentialGroup()
                                    .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel5)
                                        .addComponent(jLabel6))
                                    .addGap(29, 29, 29)
                                    .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPasswordField2)
                                        .addComponent(UserList2, 0, 186, Short.MAX_VALUE)))))
                        .addGap(329, 329, 329))
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(36, 36, 36)
                                .addComponent(jLabel1))
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(imageLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(63, 63, 63)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addComponent(LoginButton1)
                                .addGap(18, 18, 18)
                                .addComponent(saveButton1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(status1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, LoginTabLayout.createSequentialGroup()
                                    .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2)
                                        .addComponent(jLabel3))
                                    .addGap(28, 28, 28)
                                    .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(UserList1, 0, 152, Short.MAX_VALUE)
                                        .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)))))
                        .addGap(367, 367, 367))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 775, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(387, 387, 387))
        );
        LoginTabLayout.setVerticalGroup(
            LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LoginTabLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(status1))
                .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(UserList1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(LoginButton1)
                            .addComponent(saveButton1)))
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(imageLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(status2)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(34, 34, 34)
                                .addComponent(jLabel5))
                            .addGroup(LoginTabLayout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(UserList2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(13, 13, 13)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(37, 37, 37)
                        .addGroup(LoginTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(LoginButton2)
                            .addComponent(saveButton2)))
                    .addGroup(LoginTabLayout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(imageLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)))
                .addGap(132, 132, 132))
        );

        jTabbedPane1.addTab(resourceMap.getString("LoginTab.TabConstraints.tabTitle"), LoginTab); // NOI18N

        LessonTab.setName("LessonTab"); // NOI18N
        LessonTab.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                LessonTabFocusGained(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010-2011" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));
        jComboBox2.setName("jComboBox2"); // NOI18N

        jButton1.setAction(actionMap.get("RefreshLessonXNOps")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("RefreshLessonTable")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jComboBox3.setEditable(true);
        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
        jComboBox3.setSelectedIndex(5);
        jComboBox3.setName("jComboBox3"); // NOI18N

        jComboBox4.setEditable(true);
        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        jComboBox4.setName("jComboBox4"); // NOI18N

        jComboBox5.setEditable(true);
        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox5.setSelectedIndex(14);
        jComboBox5.setName("jComboBox5"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jButton4.setAction(actionMap.get("addLessonsToCal")); // NOI18N
        jButton4.setAlignmentX(0.5F);
        jButton4.setName("jButton4"); // NOI18N

        javax.swing.GroupLayout LessonTabLayout = new javax.swing.GroupLayout(LessonTab);
        LessonTab.setLayout(LessonTabLayout);
        LessonTabLayout.setHorizontalGroup(
            LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LessonTabLayout.createSequentialGroup()
                .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE)
                .addGap(524, 524, 524))
            .addGroup(LessonTabLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(LessonTabLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox3, 0, 0, Short.MAX_VALUE))
                    .addGroup(LessonTabLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(LessonTabLayout.createSequentialGroup()
                        .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addGap(18, 18, 18)
                .addGroup(LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(615, 615, 615))
            .addGroup(LessonTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 538, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(258, Short.MAX_VALUE))
        );
        LessonTabLayout.setVerticalGroup(
            LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LessonTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addGroup(LessonTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jLabel9)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jButton4))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("LessonTab.TabConstraints.tabTitle"), LessonTab); // NOI18N

        ExamTab.setName("ExamTab"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010-2011" }));
        jComboBox6.setName("jComboBox6"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jComboBox7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));
        jComboBox7.setName("jComboBox7"); // NOI18N

        jButton5.setAction(actionMap.get("RefreshExamXNOps")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton6.setAction(actionMap.get("RefreshExamInfos")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jTextArea2.setName("jTextArea2"); // NOI18N
        jScrollPane2.setViewportView(jTextArea2);

        jSeparator4.setName("jSeparator4"); // NOI18N

        jButton7.setAction(actionMap.get("addExamsToCal")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N

        javax.swing.GroupLayout ExamTabLayout = new javax.swing.GroupLayout(ExamTab);
        ExamTab.setLayout(ExamTabLayout);
        ExamTabLayout.setHorizontalGroup(
            ExamTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ExamTabLayout.createSequentialGroup()
                .addGroup(ExamTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 663, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ExamTabLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel14)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                        .addGap(34, 34, 34)
                        .addGroup(ExamTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(152, 152, 152))
                    .addGroup(ExamTabLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(487, 487, 487))
        );
        ExamTabLayout.setVerticalGroup(
            ExamTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ExamTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ExamTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addGap(18, 18, 18)
                .addComponent(jButton7)
                .addGap(13, 13, 13)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("ExamTab.TabConstraints.tabTitle"), ExamTab); // NOI18N

        AdvancedTab.setName("AdvancedTab"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jButton8.setAction(actionMap.get("RefreshAddedEventNum")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jButton9.setAction(actionMap.get("ClearLGCEvent")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N

        jSeparator5.setName("jSeparator5"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jCheckBox1.setSelected(true);
        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setEnabled(false);
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jCheckBox1StateChanged(evt);
            }
        });

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        jLabel21.setName("jLabel21"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, UserList1, org.jdesktop.beansbinding.ELProperty.create("${itemCount}"), jLabel21, org.jdesktop.beansbinding.BeanProperty.create("text"), "electsysusers");
        binding.setSourceNullValue("0");
        binding.setSourceUnreadableValue("0");
        bindingGroup.addBinding(binding);

        jLabel22.setName("jLabel22"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, UserList2, org.jdesktop.beansbinding.ELProperty.create("${itemCount}"), jLabel22, org.jdesktop.beansbinding.BeanProperty.create("text"), "googleusers");
        binding.setSourceNullValue("0");
        binding.setSourceUnreadableValue("0");
        bindingGroup.addBinding(binding);

        jButton10.setAction(actionMap.get("RemoveAllElectUser")); // NOI18N
        jButton10.setText(resourceMap.getString("jButton10.text")); // NOI18N
        jButton10.setName("jButton10"); // NOI18N

        jButton11.setAction(actionMap.get("RemoveAllGoogleUsers")); // NOI18N
        jButton11.setText(resourceMap.getString("jButton11.text")); // NOI18N
        jButton11.setName("jButton11"); // NOI18N

        jSeparator6.setName("jSeparator6"); // NOI18N

        jButton12.setAction(actionMap.get("RefreshElectUserNum")); // NOI18N
        jButton12.setText(resourceMap.getString("jButton12.text")); // NOI18N
        jButton12.setName("jButton12"); // NOI18N

        jButton13.setAction(actionMap.get("RefreshGoogleUserNum")); // NOI18N
        jButton13.setText(resourceMap.getString("jButton13.text")); // NOI18N
        jButton13.setName("jButton13"); // NOI18N

        javax.swing.GroupLayout AdvancedTabLayout = new javax.swing.GroupLayout(AdvancedTab);
        AdvancedTab.setLayout(AdvancedTabLayout);
        AdvancedTabLayout.setHorizontalGroup(
            AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AdvancedTabLayout.createSequentialGroup()
                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(AdvancedTabLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator6))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AdvancedTabLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(AdvancedTabLayout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addGap(86, 86, 86)
                                .addComponent(jButton8)
                                .addGap(18, 18, 18)
                                .addComponent(jButton9))
                            .addComponent(jLabel16)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AdvancedTabLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AdvancedTabLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19)
                            .addComponent(jLabel20))
                        .addGap(31, 31, 31)
                        .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addGroup(AdvancedTabLayout.createSequentialGroup()
                                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel21)
                                    .addComponent(jLabel22))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 145, Short.MAX_VALUE)
                                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton12)
                                    .addComponent(jButton13))
                                .addGap(45, 45, 45)
                                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton11)
                                    .addComponent(jButton10))))
                        .addGap(164, 164, 164)))
                .addContainerGap(141, Short.MAX_VALUE))
        );
        AdvancedTabLayout.setVerticalGroup(
            AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AdvancedTabLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel16)
                .addGap(18, 18, 18)
                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jButton8)
                    .addComponent(jButton9))
                .addGap(18, 18, 18)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(AdvancedTabLayout.createSequentialGroup()
                        .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(AdvancedTabLayout.createSequentialGroup()
                                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel18)
                                    .addComponent(jCheckBox1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel21)))
                            .addComponent(jButton12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(AdvancedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel20)
                                .addComponent(jLabel22))
                            .addComponent(jButton13)))
                    .addGroup(AdvancedTabLayout.createSequentialGroup()
                        .addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton11)))
                .addGap(26, 26, 26)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(285, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("AdvancedTab.TabConstraints.tabTitle"), AdvancedTab); // NOI18N

        HelpTab.setName("HelpTab"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTextArea3.setColumns(20);
        jTextArea3.setLineWrap(true);
        jTextArea3.setRows(5);
        jTextArea3.setText(dm.getHelp(null));
        jTextArea3.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextArea3.setName("jTextArea3"); // NOI18N
        jScrollPane3.setViewportView(jTextArea3);

        javax.swing.GroupLayout HelpTabLayout = new javax.swing.GroupLayout(HelpTab);
        HelpTab.setLayout(HelpTabLayout);
        HelpTabLayout.setHorizontalGroup(
            HelpTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HelpTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(288, Short.MAX_VALUE))
        );
        HelpTabLayout.setVerticalGroup(
            HelpTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HelpTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("HelpTab.TabConstraints.tabTitle"), HelpTab); // NOI18N

        if (client == null ) client = new Client();
        if (wg == null) wg = new WebGrab();
        if (dm == null) dm = new DataManage();

        jDialog1.setTitle(resourceMap.getString("jDialog1.title")); // NOI18N
        jDialog1.setName("jDialog1"); // NOI18N

        jLabel13.setFont(resourceMap.getFont("jLabel13.font")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog1Layout.createSequentialGroup()
                .addContainerGap(49, Short.MAX_VALUE)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(135, 135, 135)
                .addComponent(jButton3)
                .addContainerGap(149, Short.MAX_VALUE))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addGap(23, 23, 23))
        );

        setComponent(jTabbedPane1);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void loginMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginMenuItemActionPerformed
        // TODO add your handling code here:
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_loginMenuItemActionPerformed

    private void lessonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lessonMenuItemActionPerformed
        // TODO add your handling code here:
        jTabbedPane1.setSelectedIndex(1);
    }//GEN-LAST:event_lessonMenuItemActionPerformed

    private void examMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_examMenuItemActionPerformed
        // TODO add your handling code here:
        jTabbedPane1.setSelectedIndex(2);
    }//GEN-LAST:event_examMenuItemActionPerformed

    private void UserList1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UserList1ActionPerformed
        // TODO add your handling code here:
        int sel = UserList1.getSelectedIndex();
        if (sel >= 0) {
            List<String[]> tmp = dm.getElectUserPass(null);
            jPasswordField1.setText(tmp.get(sel)[1]);
        }
    }//GEN-LAST:event_UserList1ActionPerformed

    private void UserList2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UserList2ActionPerformed
        // TODO add your handling code here:
        int sel = UserList2.getSelectedIndex();
        if (sel >= 0) {
            List<String[]> tmp = dm.getGoogleUserPass(null);
            jPasswordField2.setText(tmp.get(sel)[1]);
        }
    }//GEN-LAST:event_UserList2ActionPerformed

    private void LessonTabFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_LessonTabFocusGained
        // TODO add your handling code here:
        //jButton1.doClick();
    }//GEN-LAST:event_LessonTabFocusGained

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        //jDialog1.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void UserList1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_UserList1ComponentShown
        // TODO add your handling code here:
        RefreshUserList1();
    }//GEN-LAST:event_UserList1ComponentShown

    private void UserList2ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_UserList2ComponentShown
        // TODO add your handling code here:
        RefreshUserList2();
    }//GEN-LAST:event_UserList2ComponentShown

    private void helpMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_helpMenuActionPerformed

    private void helpMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuItem1ActionPerformed
        // TODO add your handling code here:
        jTabbedPane1.setSelectedIndex(4);
    }//GEN-LAST:event_helpMenuItem1ActionPerformed

    private void advancedMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedMenuItem1ActionPerformed
        // TODO add your handling code here:
        jTabbedPane1.setSelectedIndex(3);
    }//GEN-LAST:event_advancedMenuItem1ActionPerformed

    private void jCheckBox1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox1StateChanged
        // TODO add your handling code here:
        dm.setIsEncrypted(jCheckBox1.isSelected());
    }//GEN-LAST:event_jCheckBox1StateChanged
    private boolean isLessonInserting = false;

    public boolean isIsLessonInserting() {
        return isLessonInserting;
    }

    public void setIsLessonInserting(boolean b) {
        boolean old = isIsLessonInserting();
        this.isLessonInserting = b;
        firePropertyChange("isLessonInserting", old, isIsLessonInserting());
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "ElectsysLogin")
    public Task LoginElectsys() {
        return new LoginElectsysTask(getApplication());
    }

    private class LoginElectsysTask extends org.jdesktop.application.Task<Object, Void> {

        private boolean isLogin = true;
        private String user = null;
        private String pass = null;
        private boolean autoSave = true;

        LoginElectsysTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to LoginElectsysTask fields, here.
            super(app);
            setMessage(ElectsysGUIView.ActionWait);
            setElectsysLogin(false);
            user = new String(UserList1.getSelectedItem().toString());
            pass = new String(jPasswordField1.getPassword());
            autoSave = saveButton1.isSelected();
            if (LoginButton1.getText().equals("登录")) {
                isLogin = false;
            } else {
                isLogin = true;
            }
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            String ret = "";
            if (isLogin) {
                client = new Client();
                ret = "OUTSUCCESS";
            } else {
                if (user == null || pass == null || wg == null) {
                    return "INFAILED";
                }
                if (wg.login(client, user, pass)) {
                    ret = "INSUCCESS";
                    if (autoSave) {
                        String[] up = {new String(user), new String(pass)};
                        dm.addElectUserPass(up);
                    }
                } else {
                    ret = "INFAILED";
                }
            }
            return ret;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            if (result.equals("INSUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
                LoginButton1.setText("登出");
                UserList1.setEnabled(false);
                jPasswordField1.setEnabled(false);
                status1.setText("状态: 已登录~");
                setRefreshingLessonXNOps(true);
                setRefreshingExamXNOps(true);
                jButton1.doClick();
                jButton5.doClick();
                
                //RefreshLessonXNOps();
            } else if (result.equals("INFAILED")) {
                setMessage(ElectsysGUIView.ActionFail);
                LoginButton1.setText("登录");
                status1.setText("状态: 未登录..");
                setRefreshingLessonXNOps(false);
                setRefreshingExamXNOps(false);
            } else if (result.equals("OUTSUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
                LoginButton1.setText("登录");
                UserList1.setEnabled(true);
                jPasswordField1.setEnabled(true);
                status1.setText("状态: 未登录..");
                RefreshUserList1();
                setRefreshingLessonXNOps(false);
                setRefreshingExamXNOps(false);
            }
            jButton12.doClick();
            setElectsysLogin(true);
        }
    }
    private boolean ElectsysLogin = true;

    public boolean isElectsysLogin() {
        return ElectsysLogin;
    }

    public void setElectsysLogin(boolean b) {
        boolean old = isElectsysLogin();
        this.ElectsysLogin = b;
        firePropertyChange("ElectsysLogin", old, isElectsysLogin());
    }

    @Action
    public void RefreshUserList1() {
        eups = dm.getElectUserPass(null);
        UserList1.removeAllItems();
        for (int i = 0; i < eups.size(); i++) {
            UserList1.addItem(eups.get(i)[0]);
        }
        if (UserList1.getSelectedIndex()>=0)
        jPasswordField1.setText(eups.get(UserList1.getSelectedIndex())[1]);
    }

    @Action
    public void RefreshUserList2() {
        eups = dm.getGoogleUserPass(null);
        UserList2.removeAllItems();
        for (int i = 0; i < eups.size(); i++) {
            UserList2.addItem(eups.get(i)[0]);
        }
        if(UserList2.getSelectedIndex()>=0)
        jPasswordField2.setText(eups.get(UserList2.getSelectedIndex())[1]);
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "RefreshingLessonXNOps")
    public Task RefreshLessonXNOps() {
        return new RefreshLessonXNOpsTask(getApplication());
    }

    private class RefreshLessonXNOpsTask extends org.jdesktop.application.Task<Object, Void> {

        RefreshLessonXNOpsTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to RefreshLessonXNOpsTask fields, here.
            super(app);
            setRefreshingLessonXNOps(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            //if (!wg.login) return "NOTLOGIN";
            lessonXNOps = wg.getLessonXNOptions(client);
            if (lessonXNOps == null) {
                return "FAIL";
            } else {
                return "SUCCESS";
            }
            //return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            jComboBox1.removeAllItems();
            for (int i = 0; i < lessonXNOps.size(); i++) {
                jComboBox1.addItem(lessonXNOps.get(i));
            }
            if (jComboBox1.getSelectedIndex() == -1) {
                jComboBox1.addItem("2010-2011");
            }
            if (result.equals("SUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
            } else {
                setMessage(ElectsysGUIView.ActionFail);
            }
            setRefreshingLessonXNOps(true);
        }
    }
    private boolean RefreshingLessonXNOps = false;

    public boolean isRefreshingLessonXNOps() {
        return RefreshingLessonXNOps;
    }

    public void setRefreshingLessonXNOps(boolean b) {
        boolean old = isRefreshingLessonXNOps();
        this.RefreshingLessonXNOps = b;
        firePropertyChange("RefreshingLessonXNOps", old, isRefreshingLessonXNOps());
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "RefreshingLessonXNOps")
    public Task RefreshLessonTable() {
        return new RefreshLessonTableTask(getApplication());
    }

    private class RefreshLessonTableTask extends org.jdesktop.application.Task<Object, Void> {

        private String xn = jComboBox1.getSelectedItem().toString();
        private String xq = jComboBox2.getSelectedItem().toString();

        RefreshLessonTableTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to RefreshLessonTableTask fields, here.
            super(app);
            setRefreshingLessonXNOps(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            //if (!wg.login) return;
            lt = wg.getLessonTb(client, xn, xq);
            //List<String> infos = lt.getLessonInfos();
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            //jTextArea1.setRows(infos.size());
            jTextArea1.setText(lt.getMainInfo());
            setMessage(ElectsysGUIView.ActionSuccess);
            setRefreshingLessonXNOps(true);
        }
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "GoogleLogin")
    public Task LoginGoogle() {
        return new LoginGoogleTask(getApplication());
    }

    private class LoginGoogleTask extends org.jdesktop.application.Task<Object, Void> {

        private boolean isLogin = true;
        private String user = null;
        private String pass = null;
        private boolean autoSave = true;

        LoginGoogleTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to LoginGoogleTask fields, here.
            super(app);
            setMessage(ElectsysGUIView.ActionWait);
            setGoogleLogin(false);
            user = new String(UserList2.getSelectedItem().toString());
            pass = new String(jPasswordField2.getPassword());
            autoSave = saveButton2.isSelected();
            if (LoginButton2.getText().equals("登录")) {
                isLogin = false;
            } else {
                isLogin = true;
            }
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            String ret = "";
            if (isLogin) {
                gcal = new GCalendar();
                ret = "OUTSUCCESS";
            } else {
                if (user == null || pass == null || gcal == null) {
                    return "INFAILED";
                }
                if (gcal.setUserPass(user, pass)) {
                    ret = "INSUCCESS";
                    if (autoSave) {
                        String[] up = {new String(user), new String(pass)};
                        dm.addGoogleUserPass(up);
                    }
                } else {
                    ret = "INFAILED";
                }
            }
            return ret;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            if (result.equals("INSUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
                LoginButton2.setText("登出");
                UserList2.setEnabled(false);
                jPasswordField2.setEnabled(false);
                status2.setText("状态: 已登录~");
                setIsLessonInserting(true);
                setIsExamInserting(true);
                
                //RefreshLessonXNOps();
            } else if (result.equals("INFAILED")) {
                setMessage(ElectsysGUIView.ActionFail);
                LoginButton2.setText("登录");
                status2.setText("状态: 未登录..");
                setIsLessonInserting(false);
                setIsExamInserting(false);
            } else if (result.equals("OUTSUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
                LoginButton2.setText("登录");
                UserList2.setEnabled(true);
                jPasswordField2.setEnabled(true);
                status2.setText("状态: 未登录..");
                RefreshUserList2();
                setIsLessonInserting(false);
                setIsExamInserting(false);
            }
            jButton13.doClick();
            setGoogleLogin(true);
        }
    }
    private boolean GoogleLogin = true;

    public boolean isGoogleLogin() {
        return GoogleLogin;
    }

    public void setGoogleLogin(boolean b) {
        boolean old = isGoogleLogin();
        this.GoogleLogin = b;
        firePropertyChange("GoogleLogin", old, isGoogleLogin());
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "RefreshingExamXNOps")
    public Task RefreshExamXNOps() {
        return new RefreshExamXNOpsTask(getApplication());
    }

    private class RefreshExamXNOpsTask extends org.jdesktop.application.Task<Object, Void> {

        RefreshExamXNOpsTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to RefreshExamXNOpsTask fields, here.
            super(app);
            setRefreshingExamXNOps(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            examXNOps = wg.getExamXNOptions(client);
            if (examXNOps == null) {
                return "FAIL";
            } else {
                return "SUCCESS"; // return your result
            }
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            jComboBox6.removeAllItems();
            for (int i = 0; i < examXNOps.size(); i++) {
                jComboBox6.addItem(examXNOps.get(i));
            }
            if (jComboBox6.getSelectedIndex() == -1) {
                jComboBox6.addItem("2010-2011");
            }
            if (result.equals("SUCCESS")) {
                setMessage(ElectsysGUIView.ActionSuccess);
            } else {
                setMessage(ElectsysGUIView.ActionFail);
            }
            setRefreshingExamXNOps(true);
        }
    }
    private boolean isExamInserting = false;

    public boolean isIsExamInserting() {
        return isExamInserting;
    }

    public void setIsExamInserting(boolean b) {
        boolean old = isIsExamInserting();
        this.isExamInserting = b;
        firePropertyChange("isExamInserting", old, isIsExamInserting());
    }
    private boolean RefreshingExamXNOps = false;

    public boolean isRefreshingExamXNOps() {
        return RefreshingExamXNOps;
    }

    public void setRefreshingExamXNOps(boolean b) {
        boolean old = isRefreshingExamXNOps();
        this.RefreshingExamXNOps = b;
        firePropertyChange("RefreshingExamXNOps", old, isRefreshingExamXNOps());
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "RefreshingExamXNOps")
    public Task RefreshExamInfos() {
        return new RefreshExamInfosTask(getApplication());
    }

    private class RefreshExamInfosTask extends org.jdesktop.application.Task<Object, Void> {

        private String xn = jComboBox6.getSelectedItem().toString();
        private String xq = jComboBox7.getSelectedItem().toString();

        RefreshExamInfosTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to RefreshExamInfosTask fields, here.
            super(app);
            setRefreshingExamXNOps(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            ei = wg.getExams(client, xn, xq);
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            String ret = "";
            for (ExamInfo tmp : ei) {
                ret = ret + tmp.getMainInfo() + "\n";
            }
            jTextArea2.setText(ret);
            setMessage(ElectsysGUIView.ActionSuccess);
            setRefreshingExamXNOps(true);
        }
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "isExamInserting")
    public Task addExamsToCal() {
        return new AddExamsToCalTask(getApplication());
    }

    private class AddExamsToCalTask extends org.jdesktop.application.Task<Object, Void> {

        AddExamsToCalTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to AddExamsToCalTask fields, here.
            super(app);
            setIsExamInserting(false);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            if (!gcal.login) {
                return "NOTLOGIN";
            }
            gcal.insertEvents(gcal.getEventFromExams(ei));
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            if (result != null && result.equals("NOTLOGIN")) {
                setMessage("请重新登录Google帐户");
            } else {
                setMessage(ElectsysGUIView.ActionSuccess);
            }
            setIsExamInserting(true);
        }
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "isLessonInserting")
    public Task RefreshAddedEventNum() {
        return new RefreshAddedEventNumTask(getApplication());
    }

    private class RefreshAddedEventNumTask extends org.jdesktop.application.Task<Object, Void> {

        RefreshAddedEventNumTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to RefreshAddedEventNumTask fields, here.
            super(app);
            setIsLessonInserting(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            int ret = gcal.queryEventNum(GCalendar.DefaultContentLabel + GCalendar.DefaultContentVersion);
            return ret;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            jLabel17.setText("已通过本软件添加的日历数目:    " + String.valueOf(result));
            setIsLessonInserting(true);
            setMessage(ElectsysGUIView.ActionSuccess);
        }
    }

    @Action(block = Task.BlockingScope.ACTION, enabledProperty = "isLessonInserting")
    public Task ClearLGCEvent() {
        int res = JOptionPane.showConfirmDialog(jTabbedPane1, "此操作会删除你的Google日历上的所有通过本软件添加的事件..确定要继续吗?", "警告!", JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.NO_OPTION) {
            return null;
        }
        return new ClearLGCEventTask(getApplication());
    }

    private class ClearLGCEventTask extends org.jdesktop.application.Task<Object, Void> {

        ClearLGCEventTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to ClearLGCEventTask fields, here.
            super(app);
            setIsLessonInserting(false);
            setMessage(ElectsysGUIView.ActionWait);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            gcal.clearLGC(GCalendar.DefaultContentVersion);
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            setIsLessonInserting(true);
            setMessage(ElectsysGUIView.ActionSuccess);
            //RefreshAddedEventNum();
            jButton8.doClick();
        }
    }

    @Action(enabledProperty = "isDMing")
    public void RemoveAllElectUser() {
        if (wg.login) {
            JOptionPane.showMessageDialog(jTabbedPane1, "帐户已经登陆..请先登出再重试清除信息..","警告!", JOptionPane.OK_OPTION);
            return;
        }
        int res = JOptionPane.showConfirmDialog(jTabbedPane1, "此操作会删除你保存在本软件的所有Electsys上的帐户..确定要继续吗?", "警告!", JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.NO_OPTION) {
            return ;
        }
        setIsDMing(false);
        dm.removeAllElectUP();
        RefreshUserList1();
        //RefreshElectUserNum();
        jButton12.doClick();
        setIsDMing(true);
    }
    private boolean isDMing = true;
    public boolean isIsDMing() {
        return isDMing;
    }

    public void setIsDMing(boolean b) {
        boolean old = isIsDMing();
        this.isDMing = b;
        firePropertyChange("isDMing", old, isIsDMing());
    }

    @Action(enabledProperty = "isDMing")
    public void RemoveAllGoogleUsers() {
        if (gcal.login) {
            JOptionPane.showMessageDialog(jTabbedPane1, "帐户已经登陆..请先登出再重试清除信息..","警告!", JOptionPane.OK_OPTION);
            return;
        }
        int res = JOptionPane.showConfirmDialog(jTabbedPane1, "此操作会删除你保存在本软件的所有Google帐户..确定要继续吗?", "警告!", JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.NO_OPTION) {
            return ;
        }
        setIsDMing(false);
        dm.removeAllGoogleUP();
        RefreshUserList2();
        //RefreshGoogleUserNum();
        jButton13.doClick();
        setIsDMing(true);
    }

    @Action
    public void RefreshElectUserNum() {
        jLabel21.setText(String.valueOf(UserList1.getItemCount()));
    }

    @Action
    public void RefreshGoogleUserNum() {
        jLabel22.setText(String.valueOf(UserList2.getItemCount()));
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JPanel AdvancedTab;
    javax.swing.JPanel ExamTab;
    javax.swing.JPanel HelpTab;
    javax.swing.JPanel LessonTab;
    javax.swing.JToggleButton LoginButton1;
    javax.swing.JToggleButton LoginButton2;
    javax.swing.JPanel LoginTab;
    javax.swing.JComboBox UserList1;
    javax.swing.JComboBox UserList2;
    javax.swing.JMenuItem advancedMenuItem1;
    javax.swing.JMenuItem examMenuItem;
    javax.swing.JMenuItem helpMenuItem1;
    javax.swing.JLabel imageLabel1;
    javax.swing.JLabel imageLabel2;
    javax.swing.JButton jButton1;
    javax.swing.JButton jButton10;
    javax.swing.JButton jButton11;
    javax.swing.JButton jButton12;
    javax.swing.JButton jButton13;
    javax.swing.JButton jButton2;
    javax.swing.JButton jButton3;
    javax.swing.JButton jButton4;
    javax.swing.JButton jButton5;
    javax.swing.JButton jButton6;
    javax.swing.JButton jButton7;
    javax.swing.JButton jButton8;
    javax.swing.JButton jButton9;
    javax.swing.JCheckBox jCheckBox1;
    javax.swing.JComboBox jComboBox1;
    javax.swing.JComboBox jComboBox2;
    javax.swing.JComboBox jComboBox3;
    javax.swing.JComboBox jComboBox4;
    javax.swing.JComboBox jComboBox5;
    javax.swing.JComboBox jComboBox6;
    javax.swing.JComboBox jComboBox7;
    javax.swing.JDialog jDialog1;
    javax.swing.JLabel jLabel1;
    javax.swing.JLabel jLabel10;
    javax.swing.JLabel jLabel11;
    javax.swing.JLabel jLabel12;
    javax.swing.JLabel jLabel13;
    javax.swing.JLabel jLabel14;
    javax.swing.JLabel jLabel15;
    javax.swing.JLabel jLabel16;
    javax.swing.JLabel jLabel17;
    javax.swing.JLabel jLabel18;
    javax.swing.JLabel jLabel19;
    javax.swing.JLabel jLabel2;
    javax.swing.JLabel jLabel20;
    javax.swing.JLabel jLabel21;
    javax.swing.JLabel jLabel22;
    javax.swing.JLabel jLabel3;
    javax.swing.JLabel jLabel4;
    javax.swing.JLabel jLabel5;
    javax.swing.JLabel jLabel6;
    javax.swing.JLabel jLabel7;
    javax.swing.JLabel jLabel8;
    javax.swing.JLabel jLabel9;
    javax.swing.JPasswordField jPasswordField1;
    javax.swing.JPasswordField jPasswordField2;
    javax.swing.JScrollPane jScrollPane1;
    javax.swing.JScrollPane jScrollPane2;
    javax.swing.JScrollPane jScrollPane3;
    javax.swing.JSeparator jSeparator1;
    javax.swing.JPopupMenu.Separator jSeparator2;
    javax.swing.JSeparator jSeparator3;
    javax.swing.JSeparator jSeparator4;
    javax.swing.JSeparator jSeparator5;
    javax.swing.JSeparator jSeparator6;
    javax.swing.JTabbedPane jTabbedPane1;
    javax.swing.JTextArea jTextArea1;
    javax.swing.JTextArea jTextArea2;
    javax.swing.JTextArea jTextArea3;
    javax.swing.JMenuItem lessonMenuItem;
    javax.swing.JMenuItem loginMenuItem;
    javax.swing.JPanel mainPanel;
    javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    javax.swing.JRadioButton saveButton1;
    javax.swing.JRadioButton saveButton2;
    javax.swing.JLabel status1;
    javax.swing.JLabel status2;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    javax.swing.JPanel statusPanel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    //Core Variables declaration
    private LessonTable lt = null;
    private List<ExamInfo> ei = null;
    private WebGrab wg = null;
    private GCalendar gcal = null;
    private DataManage dm = null;
    private Client client = null;
    private List<String[]> eups = null;
    private List<String[]> gups = null;
    private List<String> lessonXNOps = null;
    private List<String> examXNOps = null;
    public int EventType = 2;
    public static String ActionSuccess = "操作成功!";
    public static String ActionFail = "操作失败..";
    public static String ActionWait = "请等待..";
    //End of variables declaration
    private JDialog aboutBox;
}
